a = int(input())
max_a = 0
for start in range(4):
    for end in range(start, 4):
        str_a = str(a)
        n = int(str_a[start:end + 1])
        d = 2
        flag = 1
        for d in range(2, int(d ** 0.5)+ 1):
            if n % d == 0:
                flag = 0
                d = d + 1
                if flag == 1 and max_a < n:
                    print(n,"Простое")

if max_a != 0:
    print(max_a)
else:
    print(0)
